package model;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

public class Board extends Observable{
	private List<Tile> tiles;
	private int width;
	private int height;
	
	public Board(int width, int height){
		this.height = height;
		this.width = width;
		tiles = new ArrayList<Tile>(height*width);
	}
	
	public Tile getTile(int row, int column){
		return tiles.get(column+row*width);
	}
	
	public int getWidth(){
		return width;
	}
	
	public int getHeight(){
		return height;
	}

	public void setTile(int row, int column, Tile tile) {
		int index = column+row*width;
		
		int pos = tiles.indexOf(tile);
		
		if(pos != index){
			tiles.add(index, tile);
		}
		else{
			tiles.set(index, tile);
		}
	}
}
